package org.example.pingpong.common.PictureUp;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Component
public class PictureUp {

    @Value("${upload.localPath}")
    private String localPath;

    @Value("${upload.accessPath}")
    private String accessPath;

    public String upload(MultipartFile file) throws IOException {
        String fileName = UUID.randomUUID().toString() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        file.transferTo(new File(localPath + fileName));
//        String url = AliOssUtil.uploadFile(fileName, file.getInputStream());
        return accessPath + fileName;
    }
}
